# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=dlfcn

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=r19
pkgrel=1
pkgdesc="A wrapper for dlfcn to the Win32 API (mingw-w64)"
arch=('any')
url="http://code.google.com/p/dlfcn-win32"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-crt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' 'staticlibs')
source=("http://dlfcn-win32.googlecode.com/files/dlfcn-win32-${pkgver}.tar.bz2"
        'dlfcn-fix-cplusplus-linkage.patch')
md5sums=('6e321b36ee289179777bab07dcfe5510'
         '2e82b109a5a8b17be03494ff7e772c13')

prepare () {
  cd "$srcdir/dlfcn-win32-$pkgver"
  patch -p0 -i "$srcdir"/dlfcn-fix-cplusplus-linkage.patch
}

build()
{
  cd "$srcdir/dlfcn-win32-$pkgver"
  mkdir -p "build-${MINGW_CHOST}" && cd "build-${MINGW_CHOST}"
  ../configure \
    --prefix=${MINGW_PREFIX} \
    --libdir=${MINGW_PREFIX}/lib \
    --incdir=${MINGW_PREFIX}/include \
    --disable-stripping \
    --enable-shared \
    --disable-msvc
  cp ../Makefile ../dlfcn.c ../dlfcn.h .
  sed -i "s|libdl.dll |libdl-0.dll |g" Makefile
  make
}

package() {
    cd "$srcdir/dlfcn-win32-$pkgver/build-${MINGW_CHOST}"
    make DESTDIR="$pkgdir" install
}
